var UId = getParameter("UId");
var day = getParameter("Day");
var now = new Date();
var arg = 1;
$(function() {
	charts(now);
});

function charts(now) {
	if (day == 30) {
		arg = 14;
	} else if (day == 7) {
		arg = 3;
	}
	var urlStr = serverPath + "/app/doctor/diabetes/weightView.do";
	var jsonStr = '{method:"showWeightChart",UId:"' + UId + '",date:"'
			+ now.format("yyyy-MM-dd") + '",day:"' + day + '",befdate:"'
			+ getLastDay(now, arg).format("yyyy-MM-dd") + '",aftdate:"'
			+ getNextDay(now, arg).format("yyyy-MM-dd") + '"}';
	// alert(jsonStr);
	UseAjax(urlStr, jsonStr, document.cookie, rt, '1');
}
function rt(data) {
	var height = Number(data.height) / 100;
	var records = data.records;
	var html = "";
	html = '<table class="bordered"><thead> '
			+ '<tr><th>日期</th><th>时间</th><th>体重</th><th>BMI</th> '
			+ '</tr></thead>';
	if (records.length > 0) {
		for (var int = 0; int < records.length; int++) {
			var wi = records[int];// .substring(0,10)
			html += '<tr><td>' + wi.dates.substring(5, 10) + '</td><td>'
					+ wi.dates.substring(11, 16) + '</td><td>' + wi.value
					+ '</td><td>'
					+ (Number(wi.value) / (height * height)).toFixed(1)
					+ '</td></tr>';
		}
	}
	$("#container").html(html);
}

$(function() {
	// swipe 的dome
	$("#container").swipe(
			{
				swipeLeft : function(event, direction, distance, duration,
						fingerCount) {

					now = getNextDay(now, arg);
					charts(now);
				},
				swipeRight : function(event, direction, distance, duration,
						fingerCount) {
					now = getLastDay(now, arg);
					charts(now);
				},
			});

});
